﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/BackSite.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    管理人员信息
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="TablePlaceHolder" runat="server">
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="TitlePlaceHolder" runat="server">
    <div id="title" style="background-image: url('../../Content/images/toolbar_bg.gif'); background-repeat: repeat-x">
        <span class="font16 fLeft" style="font-size: 26px"><strong>管理人员信息</strong></span><span class="fRight mR10 mT08"></span>
    </div>
    <p>
    </p>
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <script type="text/javascript">
        Ext.onReady(function () {

            function setChecked() { return true; }

            Ext.define('MyData', {
                extend: 'Ext.data.Model',
                fields: ['active',
                        //第一个字段需要指定mapping，其他字段，可以省略掉。   
                         'User_ID',
                         'Dep_ID',
                         'User_Name',
                         'Sex',
                         'Privilege',
                         'ID',
                         'Cellphone',
                         'Address',
                         'Status'
                ]
            });
            //创建数据源   
            store = Ext.create('Ext.data.Store', {
                model: 'MyData',
                autoLoad: true,
                pageSize: 16,
                remoteFilter: true,
                remoteSort: true,
                proxy: {
                    //异步获取数据，这里的URL可以改为任何动态页面，只要返回JSON数据即可   
                    type: 'ajax',
                    //url: 'UsersQuery',
                    api: {
                        read: 'UsersQuery',
                        create: '../../Handlers/UserOperation.ashx?act=add',
                        destroy: '../../Handlers/UserOperation.ashx?act=del',
                        update: '../../Handlers/UserOperation.ashx?act=edit'
                    },
                    reader: {
                        type: 'json',
                        root: 'data',
                        totalProperty: 'total'
                    },
                    writer: {
                        type: "json",
                        encode: true,//encode和root是配套使用的，只有设置了root时，encode才起作用
                        root: "data",//设置root的好处就是可通过习惯的方式在后台提取数据
                        allowSingle: false//不然还得判断提交数据是数组还是对象
                    }
                }
            });

            //function button() {
            //    return '<input type="button" value="编辑" />';
            //}

            //创建Grid   
            grid = Ext.create('Ext.grid.Panel', {
                store: store,
                selModel: { selType: "checkboxmodel", checkOnly: true, mode: "MULTI" },
                plugins: [{
                    ptype: "cellediting",
                    listeners: {
                        edit: function (edit, e) {
                            if (e.field == "User_ID") {
                                var regionStore = Ext.StoreManager.lookup("RegionStore");
                                var rec = regionStore.getById(e.value);
                                e.record.set("RegionDescription", rec.data.RegionDescription);
                            }
                        }
                    }
                }], columns: [
                        { xtype: 'rownumberer' },
                        //{ xtype: 'checkcolumn', text: '选择', dataIndex: 'active', checked: true, width: 100 },
                        { text: "用户ID", width: 100, dataIndex: 'User_ID', sortable: true },
                        { text: "部门ID", width: 100, dataIndex: 'Dep_ID', sortable: true },
                        { text: "用户名", width: 100, dataIndex: 'User_Name', sortable: true, field: { xtype: "textfield", allowBlank: false } },
                        { text: "性别", width: 50, dataIndex: 'Sex', sortable: true, field: { xtype: "combobox", store: ["男", "女"] } },
                        { text: "权限", width: 100, dataIndex: 'Privilege', sortable: true, field: { xtype: "textfield", allowBlank: false } },
                        { text: "身份证号", width: 200, dataIndex: 'ID', sortable: true, field: { xtype: "textfield", allowBlank: false } },
                        { text: "手机号", width: 150, dataIndex: 'Cellphone', sortable: true, field: { xtype: "textfield", allowBlank: false } },
                        { text: "地址", width: 100, dataIndex: 'Address', sortable: true, field: { xtype: "textfield", allowBlank: false } },
                        { text: "状态", width: 100, dataIndex: 'Status', sortable: true, field: { xtype: "combobox", store: ["有效", "锁定", "注销"] } }
                ],

                dockedItems: [{
                    xtype: 'toolbar',
                    height: '50px',
                    width: 500,
                    items: [{
                        text: "增加", id: "add", icon: '../../Content/images/add.gif', handler: function () {
                            var grid = this.up("gridpanel");
                            var edit = grid.plugins[0];
                            var rec = new MyData({
                                User_ID: "aef",
                                Dep_ID: "fff",
                                Status: "有效"
                            });
                            edit.cancelEdit();
                            grid.store.insert(0, rec);
                            edit.startEditByPosition({ row: 0, column: 2 });
                        }
                    }, '-', {
                        itemId: 'delete',
                        text: '删除',
                        id: "delete",
                        icon: '../../Content/images/delete.gif',
                        disabled: true,
                        handler: function () {
                            var grid = this.up("gridpanel");
                            var rs = grid.getSelectionModel().getSelection();
                            if (rs.length > 0) {
                                Ext.Msg.confirm('提示', '确认删除？', function (btn) {
                                    if (btn == "yes") {
                                        this.store.remove(this.getSelectionModel().getSelection());
                                        store.sync();
                                    }
                                }, grid)
                            }
                        }
                    }, '-', {
                        itemId: 'save',
                        text: '保存',
                        id: "save",
                        icon: '../../Content/images/save.gif',
                        handler: function () {
                            store.sync();
                        }
                    }, '-', {
                        itemId: 'export',
                        text: '导出到Excel',
                        icon: '../../Content/images/application_go.png',
                        disabled: false,
                        handler: function () {
                            var selection = grid.getView().getSelectionModel().getSelection()[0];
                            if (selection) {
                                store.remove(selection);
                            }
                        }
                    }, '-',
                    {
                        xtype: 'exporterbutton',
                        store: store,
                        //                            //以下两项配置已在Buttion.js中配置默认路径 不需要重复指定， 有需要者可自行修改
                        swfpath: 'downloadify.swf',
                        //downloadImage: 'download.png',
                        //
                        //                            //这里可以根据当前表格指定导出的文件名
                        downloadName: '用户列表'
                    }]
                }],
                bbar: new Ext.PagingToolbar({
                    pageSize: 10,
                    store: store,
                    displayInfo: true,
                    displayMsg: '显示第{0}条到{1}条记录，一共{2}条',
                    emptyMsg: "没有记录"
                }),
                height: 460,
                x: 0,
                y: 0,
                title: '人员信息列表',
                renderTo: 'grid',
                viewConfig: {
                    stripeRows: true
                },
                listeners: {
                    selectionchange: function (view, rs) {
                        Ext.getCmp("delete").setDisabled(rs.length == 0);
                    }
                }
            })
            //创建Grid结束

            //function showDelMess() {
            //    Ext.MessageBox.confirm('提示', '确认删除？', doDel);
            //}

            //function doDel(btn) {
            //    if (btn == 'yes') {
            //        var row = grid.getSelections();
            //        var jsonData = "";
            //        for (var i = 0, len = row.length; i < len; i++) {
            //            var ss = row[i].get("ID");
            //            jsonData = jsonData + ss + ",";
            //        }
            //        if (jsonData.length == 0) {
            //            Ext.MessageBox.alert('提示', '删除失败！');
            //        } else {
            //            Ext.lib.Ajax.request(
            //                        'GET',
            //                        '../../Handlers/logMaster_Data.aspx?event=delete&delData=' + jsonData,
            //                        {
            //                            success: function (form, action) {
            //                                Ext.MessageBox.alert('删除成功！');
            //                                store.reload();
            //                            },
            //                            failure: function (form, action) {
            //                                Ext.MessageBox.show({
            //                                    title: '提示',
            //                                    msg: '删除失败！',
            //                                    buttons: Ext.Msg.OK,
            //                                    icon: Ext.MessageBox.ERROR
            //                                });
            //                            }
            //                        },
            //                        null
            //                    );
            //        }
            //    }
            //}
        })

        $(document).ready(function () {
            //点击“查询”按钮后进行刷新
            $("#btnSearch").click(function () {
                var User_Name = document.getElementById("txtName").value;
                var User_ID = document.getElementById("txtUserId").value;
                    //store前一定不能加var
                    store.currentPage = 1;
                    store.filters.clear();
                    store.filter([{ property: 'User_ID', value: User_ID }, { property: 'User_Name', value: User_Name }]);
                    //store.proxy.extraParams.key = search;
                    //store.load();

                    //User_Name = "User_Name";
                    //end = "EndDate";
                    //params = store.getProxy().extraParams;
                    //params.User_Name = User_Name;
                    //params.end = end;
                    ////store.filters.clear();
                    ////store.filter(params);
                    //store.prefetchData.clear();
                    //store.MyFilter = true;
                    //if (store.currentPage == 1) {
                    //    store.load();
                    //} else {
                    //    store.guaranteeRange(0, 15);
                    //}
            });

            $("#btnShowAll").click(function () {
                store.currentPage = 1;
                store.clearFilter();
                $("#txtUserId").val = "";
                document.getElementById("txtUserId").value = "";
                document.getElementById("txtName").value = "";
            });

        });
    </script>
    <table style="margin: 0; padding: 0; border: 0; outline: 0; font-weight: inherit; font-style: inherit; font-size: 100%; font-family: inherit; vertical-align: baseline;">
        <tr>
            <td style="margin: 0; padding: 0; border: 0; outline: 0; font-weight: inherit; font-style: inherit; font-size: 100%; font-family: inherit; vertical-align: baseline;">&nbsp;人员编号：<input id="txtUserId" type="text" style="width: 95px" />&nbsp;&nbsp;&nbsp;作业区： 
                <select id="Select5" name="D5">
                    <option>第一作业区</option>
                    <option>第二作业区</option>
                    <option>第三作业区</option>
                </select>&nbsp; 大队：<select id="Select2" name="D2">
                    <option>第一采油大队</option>
                    <option>第二采油大队</option>
                    <option>第三采油大队</option>
                </select>&nbsp;&nbsp;&nbsp;小队：<select id="Select3" name="D3">
                    <option>第一采油小队</option>
                    <option>第二采油小队</option>
                    <option>第三采油小队</option>
                </select>&nbsp;&nbsp;&nbsp;姓名：<input id="txtName" type="text" style="width: 103px" />&nbsp;&nbsp;&nbsp;&nbsp;
                <input id="btnSearch" type="button" value="查询" />&nbsp;
                <input id="btnShowAll" type="button" value="显示全部" style="width: 66px" /><br />
            </td>
        </tr>
    </table>

    <div id="grid"></div>
</asp:Content>

<asp:Content ID="Content5" ContentPlaceHolderID="TableHeadPlaceHolder" runat="server">
</asp:Content>
